<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        body, html {
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }

        #container {
            width: 100%;
            height: 100%;
        }

        #result {
            position: fixed;
            top: 10px;
            left: 20px;
            width: 300px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            background: #fff;
            box-shadow: 0 2px 6px 0 rgba(27, 142, 236, 0.5);
            border-radius: 7px;
            z-index: 99;
        }
    </style>
    <script type="text/javascript"
            src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=1Ft3QXPFRTdpQgrFSBRXeX6SfznICmeO">

    </script>
    <script language="javascript" type="text/javascript" src="js/Kunyi.Respond.min.js"></script>
    <![endif]-->
    <script language="javascript" type="text/javascript" src="js/KunyiHTML5.min.js"></script>
    <script language="javascript" type="text/javascript" src="js/Kunyilibrary.js"></script>
</head>
</head>
<body>
<div id="container"></div>
<div id="result">根据起点和终点经纬度驾车导航路线</div>
<script type="text/javascript">



    $.ajax({
        type: "get",
        url: "/map/addr",
        data: {},
        contentType: "application/x-www-form-urlencoded",
        dataType: "json",
        success: function (data) { // 成功拿到结果放到这个函数 data就是拿到的结果
            console.log(data);

            let map = new BMapGL.Map("container");
            map.centerAndZoom(new BMapGL.Point(120.404, 39.915), 19);
            map.enableScrollWheelZoom(true);
            let output = "从到中山医院驾车需要";
            let searchComplete = function (results) {
                if (transit.getStatus() != BMAP_STATUS_SUCCESS) {
                    return;
                }
                let plan = results.getPlan(0);
                output += plan.getDuration(true) + "\n";                //获取时间
                output += "总路程为：";
                output += plan.getDistance(true) + "\n";             //获取距离
            }
            let transit = new BMapGL.DrivingRoute(map, {
                renderOptions: {map: map},
                onSearchComplete: searchComplete,
                onPolylinesSet: function () {
                    setTimeout(function () {
                        alert(output)
                    }, "1000");
                }
            });
            let start = new BMapGL.Point(data.content.point.x, data.content.point.y);
            // var start = new BMapGL.Point(118.059395,24.612685);
            let end = new BMapGL.Point(118.104179, 24.47806);
            // var driving = new BMapGL.DrivingRoute(map, {renderOptions:{map: map, autoViewport: true}});
            transit.search(start, end);
        },
        error: function () {//失败的函数
            alert("error")
        },

    })



</script>
</body>
</html>